﻿'=======================================================================================================================================
'
' Programmer:       Michael Williams
'
'
'
'
'
'
'
'=======================================================================================================================================
' Dependencies:
'=======================================================================================================================================
'
'
'
'
'
'=======================================================================================================================================
' Considerations:
'=======================================================================================================================================
'
'
'
'
'=======================================================================================================================================



' Compiler Options:
Option Explicit On
Option Strict On
Option Infer Off

'=========================================================================
' Explosed Properties:
'=========================================================================
'   Word 
'   Context
'   Definition
'
'
'==========================================================================

'=========================================================================
' Explosed Functions:
'=========================================================================
'   IsCharacterCorrect
'   NextWord
'   NextLesson
'
'
'==========================================================================



Public Class SpellingLessonMW
    Dim m_oWordsToSpellMW As New WordsToSpellMW

    ' NOTE: Expose only the properties that the GUI needs to access from the Form.
    '       These are a duplicate of the WordMW class properties but ReadOnly.
    Public ReadOnly Property word() As String
        Get
            Return m_oWordsToSpellMW.word
        End Get
    End Property


    Public ReadOnly Property context() As String
        Get
            Return m_oWordsToSpellMW.context
        End Get
    End Property



    Public ReadOnly Property definition() As String
        Get
            Return m_oWordsToSpellMW.definition
        End Get
    End Property


    Public ReadOnly Property wordComplete() As Boolean
        Get
            Return m_oWordsToSpellMW.wordComplete
        End Get
    End Property


    Public ReadOnly Property currentCharactersCorrect() As String
        Get
            Return m_oWordsToSpellMW.currentCharactersCorrect
        End Get
    End Property


    Public Property hintGiven() As Boolean
        Get
            Return m_oWordsToSpellMW.hintGiven
        End Get
        Set(value As Boolean)
            m_oWordsToSpellMW.hintGiven = value
        End Set
    End Property

    Public Sub New()
        ' NOTE: The reason you must call the New method of the base class is that the base class
        '       might have its own constructor, which can't be called directly.
        MyBase.New()

        ' TODOMW: remove this sub if no extra code added below.

    End Sub

    Public Function GetWordContextAndDefinition(ByVal labelSpeaking As Boolean) As String
        'NOTE: Build the string to say. Best to build as long string so when stopping speech it stop full sentance.
        Dim result As String

        'TODOMW: User can override in Options > settings to not speak the label Spell: etc before the word.
        If labelSpeaking = True Then
            result = "Spell: " & word & ". "
            If Not IsNothing(context) Then
                ' Only speak label if context exists.
                result += "Context: " & context & ". "
            End If

            If Not IsNothing(definition) Then
                ' Only speak label if definition exists.
                result += "Definition: " & definition & ". "
            End If
            result += "Spell: " & word & ". "
        Else
            result = word & ". " _
                & context & ". " _
                & definition _
                & word
        End If

        Return result
    End Function



    Public Function IsCharacterCorrect(ByVal character As Char) As Boolean
        ' This function is not case sensitive.

        Dim result As Boolean

        If UCase(character) = UCase(m_oWordsToSpellMW.currentCharacter) Then
            ' Character is correct.
            result = True
            ' Move to the next character in the word to spell.
            m_oWordsToSpellMW.NextCharacter()
        Else
            ' Character is incorrect. So don't move onto the next character until correct.
            result = False
        End If

        Return result

        ' TODOMW: Does the ToUpper function of the char type do the same thing as UCase?
        '//character.ToUpper()
    End Function

    Public Function NextWord() As Boolean
        Dim result As Boolean

        If m_oWordsToSpellMW.NextWord(hintGiven) = True Then
            result = True
        Else
            result = False
        End If

        Return result
    End Function

    Public Function NextLesson() As Boolean
        Dim result As Boolean

        If m_oWordsToSpellMW.NextLesson() = True Then
            result = True
        Else
            result = False
        End If

        Return result
    End Function
End Class
